<template>
  <Container class="storeresign-list">
    <HeadFormItem
      slot="header"
      :list="list"
      @onSearchBtnClick="onSearchBtnClick"
    />
    <Tabs v-model="tab">
      <div slot="extra">
        <Button
          size="large"
          class="item"
          type="primary"
          icon="md-add"
          @click="add">新增</Button>
      </div>

      <TabPane label="经销商条码盘存" name="tab1">
        <homeTable
          :list="list"
          @getData="getData"
          @onPageSizeChange="onPageSizeChange"
          @onPageChange="onPageChange"
          @onSelectionChange="onSelectionChange"
        />
      </TabPane>
    </Tabs>
    <BarCodeModelItem ref="BarCodeModel" />
    <BarCodeDetailModelItem ref="BarCodeDetailModel" />
  </Container>
</template>
<script>
import BarCodeListData from './list/BarCodeListData'
import HeadFormItem from './list/HeadFormItem'
import BarCodeModelItem from './list/BarCodeModelItem'
import BarCodeDetailModelItem from './list/BarCodeDetailModelItem'
import homeTable from '@/components/homeTable'

import { clearEmpty } from '@/util'
export default {
  name: 'manage/code/list',
  components: {
    HeadFormItem,
    BarCodeModelItem,
    BarCodeDetailModelItem,
    homeTable
  },
  data() {
    return {
      tab: "tab1",
      list: BarCodeListData,
      productIds: []
    };
  },
  mounted() {
    this.getData();
    this.$bus.$on('detailInfo', this.detailInfo)
  },
  destroyed() {
    this.$bus.$off();
  },
  methods: {
    onSearchBtnClick() {
      this.list.currentPage = 1;
      this.getData();
    },
    add() {
      this.$refs.BarCodeModel.openModal()
    },
    detailInfo(row) {
      this.$refs.BarCodeDetailModel.openModal(row)
    },
    getData() {
      this.productIds = [];
      this.list.status = "loading";
      let param = {
        current: this.list.currentPage,
        size: this.list.pageSize,
        ...this.list.form
      };
      param = clearEmpty(param)
      this.$jsonPost("/distributorInventory/findQuery", param).then(res => {
        let data = res.query
        this.list.data = [];
        this.list.totalItem = Number(data.total);
        this.list.data = (data.records || [])
        this.list.status = "pass";
      })
      .catch(() => {
        this.list.status = "error";
      });
    },
    onSelectionChange(selection) {
      this.productIds = (selection || []).map(item => item.id);
    },
    onPageChange(number) {
      this.list.currentPage = number;
      this.getData();
    },
    onPageSizeChange(pageSize) {
      this.list.currentPage = 1;
      this.list.pageSize = pageSize;
      this.getData();
    },
    onRefresh() {
      this.getData();
    },
    onExport() {
      this.$Message.info('导出')
    },
  },
  watch: {
  }
};
</script>
